package cn.nfwx.tv.fragment.dialog;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.nfwx.tv.R;
import cn.nfwx.tv.base.BaseDialogFragment;

/**
 * Created by zhouzechao on 2018/2/2.
 */
public class WifiSelectDialogFragment extends BaseDialogFragment {

    private static String KEY_WIFI = "KEY_WIFI";

    public static WifiSelectDialogFragment newInstance(ArrayList<String> wifis) {
        WifiSelectDialogFragment wifiSelectDialogFragment = new WifiSelectDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putStringArrayList(KEY_WIFI, wifis);
        wifiSelectDialogFragment.setArguments(bundle);
        return wifiSelectDialogFragment;
    }

    /**
     * 是否填满整个屏幕
     */
    protected boolean isMatchParent() {
        return false;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_wifi_select;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        List<String> wifi = getArguments().getStringArrayList(KEY_WIFI);
        LinearLayout ll_wifi = findView(R.id.ll_wifi);
        for (final String wifiStr : wifi) {
            TextView textView = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.item_wifi, null);
            textView.setText(wifiStr);
            View view = new View(getContext());
            view.setBackgroundResource(R.color.line_color);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2);
            params.setMargins((int) getResources().getDimension(R.dimen.dp15), 0, (int) getResources().getDimension(R.dimen.dp15), 0);
            ll_wifi.addView(textView);
            ll_wifi.addView(view, params);
            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //WifiHelper.getInstance().disconnect();
                    //WifiHelper.getInstance().connentWifi(wifiStr);
                    dismissAllowingStateLoss();
                }
            });
        }
        findView(R.id.btn_cancle).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismissAllowingStateLoss();
            }
        });
    }
}
